﻿using System;
using System.Linq;
using nRoute.Controllers;
using nRoute.Controllers.Mapping;
using Officer2010.Infrastructure.ViewServices;
using nRoute.Components.Composition;

namespace Officer2010.Controllers
{
    [MapController("Shell/ShowBallon/{message}/")]
    public class ShellBallonController
        : Controller
    {
        private readonly IMessageViewService _showMessageViewService;

        [ResolveConstructor]
        public ShellBallonController(IMessageViewService showMessageViewService)
        {
            if (showMessageViewService == null) throw new ArgumentNullException("showMessageViewService");
            _showMessageViewService = showMessageViewService;
        }

        public void Index(string message)
        {
            if (string.IsNullOrEmpty(message)) return;
            _showMessageViewService.ShowMessage(SpaceMessage(message));
        }

#region Helpers

        private static string SpaceMessage(string message)
        {
            if (string.IsNullOrEmpty(message)) return null;

            var _chars = message.ToCharArray().Where(Char.IsUpper).ToList();
            foreach (var _char in _chars)
            {
                message = message.Replace(_char.ToString(), " " + _char);
            }
            return message.Trim().Replace("  ", " ");
        }

#endregion

    }
}
